﻿@using GC_RF.Site.Resources.Constants
@model GC_RF.Site.Models.Shared.DisplayTemplates.PagerModel
@{
	Layout = null;
}
<div class="pagination">
	<ul>
		@{
			//Prev Page
			<li>
				<span @Html.Raw(Model.PageNumber <= 1 ? "class='disabledPrevNext'" : string.Empty) data-page="@(Model.PageNumber - 1)">&laquo;</span>
			</li>

			//First Page
			<li>
				<span @Html.Raw(Model.PageNumber == 1 ? "class='currentPage'" : string.Empty) data-page="1">1</span>
			</li>

			//First ...
			@Html.Raw(Model.PageNumber + UIHelper.CountPagesBothSideCurrPage >= UIHelper.MaxCountVisiblePages && Model.PageCount > UIHelper.MaxCountVisiblePages ? "<li>...</li>" : string.Empty)

			//Pages
			if (Model.PageCount > 2)
			{
				var pageNumber = Model.PageNumber - UIHelper.CountPagesBothSideCurrPage <= 1 || Model.PageCount <= UIHelper.MaxCountVisiblePages
					? 2
					: Model.PageCount - UIHelper.CountPagesBothSideCurrPage <= Model.PageNumber
						? Model.PageCount - UIHelper.CountPagesBothSideCurrPage * 2 - 1
						: Model.PageNumber - UIHelper.CountPagesBothSideCurrPage;

				for (var i = 0; i < UIHelper.CountPagesBothSideCurrPage * 2 + 1 && pageNumber < Model.PageCount; i++)
				{
					<li><span @Html.Raw(pageNumber == Model.PageNumber ? "class='currentPage'" : string.Empty) data-page="@pageNumber">@pageNumber</span></li>
					pageNumber++;
				}
			}

			//Last ...
			@Html.Raw(Model.PageNumber + UIHelper.CountPagesBothSideCurrPage + 1 < Model.PageCount && Model.PageCount > UIHelper.MaxCountVisiblePages ? "<li>...</li>" : string.Empty)

			//Last Page
			if (Model.PageCount != 1)
			{
				<li>
					<span @Html.Raw(Model.PageNumber == Model.PageCount ? "class='currentPage'" : string.Empty) data-page="@Model.PageCount">@Model.PageCount</span>
				</li>
			}

			//Next Page
			<li>
				<span @Html.Raw(Model.PageNumber >= Model.PageCount ? "class='disabledPrevNext'" : string.Empty) data-page="@(Model.PageNumber + 1)">&raquo;</span>
			</li>
		}
	</ul>
</div>